<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>

<c:choose>
    <c:when test="${null != actionBean.resultMenuItem}">
        <div id="addMenuViewDiv">
            <stripes:form id="menuItemAddFrom" beanclass="com.feib.soeasy.action.Soez9003ActionBean" 
                method="post">        
                <table id="MenuItemTable">
                    <tr>
                        <th>程式類別</th>
                        <td>
                            <select id="menuTypex" name="menuType">
                                <option value="0" <c:if test="${empty actionBean.resultMenuItem.parentMenuItem }">selected="selected"</c:if> >程式群組</option>
                                <option value="1" <c:if test="${!empty actionBean.resultMenuItem.parentMenuItem }">selected="selected"</c:if>>程式功能</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th>上層程式</th>
                        <td>
                            <stripes:select id="parentMenuIdx" name="resultMenuItem.parentMenuItem.menuItemPk" >
                                <stripes:option value="">-- 請選擇 --</stripes:option>
                                <stripes:options-collection collection="${actionBean.parentMenuItemOptions }" label="label" value="value"/>
                            </stripes:select>   
                            <font color="red">若程式類別為程式群組, 則不能輸入<br>若為程式功能, 則必選</font>                    
                        </td>
                    </tr>
                    <tr>
                        <th>程式代號<span id="mustKeyInStar">**</span></th>
                        <td>
                            <stripes:text id="menuIdx" name="resultMenuItem.menuId" size="30" maxlength="50" />
                        </td>
                    </tr>                
                    <tr>
                        <th>程式名稱<span id="mustKeyInStar">**</span></th>
                        <td>
                            <stripes:text id="actionNamex" name="resultMenuItem.actionName" size="30" maxlength="50" />
                        </td>
                    </tr>
                    <tr>
                        <th>程式PAGE</th>
                        <td>
                            <stripes:text id="actionPagex" name="resultMenuItem.actionPage" size="30" maxlength="50" />
                        </td>
                    </tr>
                    <tr>
                        <th>程式類別名稱</th>
                        <td>
                            <stripes:text id="actionBeanx" name="resultMenuItem.actionBean" size="30" maxlength="50" />
                        </td>
                    </tr>
                    <tr>
                        <th>排序</th>
                        <td>
                            <stripes:text id="orderNox" name="resultMenuItem.orderNo" size="30" maxlength="50" />
                        </td>
                    </tr>                    
                    <tr>
                        <th>是否有效</th>
                        <td>
                            <select id="enabledx" name="resultMenuItem.enabled">
                                <option value="True" <c:if test="${actionBean.resultMenuItem.enabled }">selected="selected"</c:if> >啟用</option>
                                <option value="False" <c:if test="${!actionBean.resultMenuItem.enabled }">selected="selected"</c:if>>停用</option>
                            </select>   
                        </td>
                    </tr>                   
                    <tr>
                        <th>學校可用</th>
                        <td>
                            <select id="schoolx" name="resultMenuItem.school">
                                <option value="True" <c:if test="${actionBean.resultMenuItem.school }">selected="selected"</c:if> >啟用</option>
                                <option value="False" <c:if test="${!actionBean.resultMenuItem.school }">selected="selected"</c:if>>停用</option>
                            </select>   
                        </td>
                    </tr>                  
                    <tr>
                        <th>一般收費可用</th>
                        <td>
                            <select id="committeex" name="resultMenuItem.committee">
                                <option value="True" <c:if test="${actionBean.resultMenuItem.committee }">selected="selected"</c:if> >啟用</option>
                                <option value="False" <c:if test="${!actionBean.resultMenuItem.committee }">selected="selected"</c:if>>停用</option>
                            </select>   
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" class="queryFunction">
                            <stripes:button id="doSaveBtn" name="doSaveBtn" value="確認" class="formBtn"/>
							<input type="button" id="closeAddMenuItemBtn" value="離開" class="formBtn"/>
                        </td>
                    </tr>                   
                </table>
            </stripes:form>    
        </div>
        <div id="saveMenuItemHiddenFormDiv" style="display: none; ">
            <stripes:form id="saveMenuItemHiddenFrom" beanclass="com.feib.soeasy.action.Soez9003ActionBean" 
                method="post" onsubmit="javascript: return false;">         
                <input type="hidden" id="hidden5.menuType" name="resultMenuItem.menuType"/>  
                <input type="hidden" id="hidden5.resultMenuItem.parentMenuItem.menuItemPk" name="resultMenuItem.parentMenuItem.menuItemPk"/>
                <input type="hidden" id="hidden5.resultMenuItem.menuId" name="resultMenuItem.menuId"/>                    
                <input type="hidden" id="hidden5.resultMenuItem.actionName" name="resultMenuItem.actionName"/>
                <input type="hidden" id="hidden5.resultMenuItem.actionPage" name="resultMenuItem.actionPage"/>
                <input type="hidden" id="hidden5.resultMenuItem.actionBean" name="resultMenuItem.actionBean"/>
                <input type="hidden" id="hidden5.resultMenuItem.orderNo" name="resultMenuItem.orderNo"/>
                <input type="hidden" id="hidden5.resultMenuItem.enabled" name="resultMenuItem.enabled"/>
                <input type="hidden" id="hidden5.resultMenuItem.school" name="resultMenuItem.school"/>
                <input type="hidden" id="hidden5.resultMenuItem.committee" name="resultMenuItem.committee"/>
                <input type="hidden" id="method6" name="doMenuItemAddAction"/>
            </stripes:form>
        </div>
        <div id="saveMenuItemMsgDiv" style="display: none; ">
        </div> 
        <script type="text/javascript">
        <!--
            $(document).ready(function() {
                $("#doSaveBtn").click(function() {
                    var menuType = $('#menuTypex').val();
                    var parentMenuId = $('#parentMenuIdx').val();
                    var menuId = $('#menuIdx').val();
                    var actionName = $('#actionNamex').val();
                    var actionPage = $('#actionPagex').val();
                    var actionBean = $('#actionBeanx').val();
                    var orderNo = $('#orderNox').val();
                    var enabled = $('#enabledx').val();
                    var school = $('#schoolx').val();
                    var committee = $('#committeex').val();
                    
                    $('#hidden5\\.menuType').val(menuType);
                    $('#hidden5\\.resultMenuItem\\.parentMenuItem\\.menuItemPk').val(parentMenuId);
                    $('#hidden5\\.resultMenuItem\\.menuId').val(menuId);
                    $('#hidden5\\.resultMenuItem\\.actionName').val(actionName);
                    $('#hidden5\\.resultMenuItem\\.actionPage').val(actionPage);
                    $('#hidden5\\.resultMenuItem\\.actionBean').val(actionBean);
                    $('#hidden5\\.resultMenuItem\\.orderNo').val(orderNo);
                    $('#hidden5\\.resultMenuItem\\.enabled').val(enabled);
                    $('#hidden5\\.resultMenuItem\\.school').val(school);
                    $('#hidden5\\.resultMenuItem\\.committee').val(committee);
                    
                    var errorMessage = '';

	                
	                if (null == menuId || 0 == menuId.length){
	                	errorMessage = errorMessage + "程式代號是必要欄位<br />";
	    			}
	                if (null == actionName || 0 == actionName.length){
	                	errorMessage = errorMessage + "程式名稱是必要欄位<br />";
	    			}
	                if (menuType == '1' )
	                	if  (null == actionPage || 0 == actionPage.length)
							  errorMessage = errorMessage +'程式類別為程式功能, 則程式PAGE是必要欄位<br />';
	                
	                if (menuType == '1' ) 
	                    if  (null == actionBean || 0 == actionBean.length)
	                	errorMessage = errorMessage +'程式類別為程式功能, 則程式類別名稱 是必要欄位<br />';
                                     
                    
                    if (menuType == '0' && parentMenuId != '') 
                        errorMessage = errorMessage +'程式類別為程式群組, 則不能選擇上層程式<br />';
                    if (menuType == '1' && parentMenuId == '') 
                        errorMessage = errorMessage +'程式類別為程式功能, 請選擇上層程式<br />';
                    
                    if (null != orderNo && 0 != orderNo.length){
                    	var checkNum = parseInt(orderNo, 10);
                    	if(isNaN(checkNum))
                    		errorMessage = errorMessage +'排序須為整數 <br />';
                    }
                    
                    if (0 != errorMessage.length){
        				$("#ajaxErrorMessageDiv").html(errorMessage);
        				$("#ajaxErrorMessageDiv" ).dialog({  
        					title:'請修正下列錯誤' 
        					,width: 300
        					, resizable: false
        					, modal: true
        					, buttons: {
        						Ok: function() {
        							$( this ).dialog( "close" );
        						}
        					}
        				});
        				
        				return false;
        			}
                               
                    
                    waitingDialog({});
                    $.ajax({url : "<c:url value='/ajax/Soez9003.action'/>",
                        async : false,
                        type : 'POST',
                        data : $("#saveMenuItemHiddenFrom").serialize(),
                        dataType : 'html',
                        success : function(data, textStatus, XMLHttpRequest){
                                $("#addMenuViewDiv").hide();
                                $("#saveMenuItemMsgDiv" ).html(data);
                                $("#saveMenuItemMsgDiv").show();
                            },
                        error : function(XMLHttpRequest, textStatus, errorThrown){
                            $("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
                            $("#ajaxErrorMessageDiv" ).dialog( "destroy" );
                            $("#ajaxErrorMessageDiv" ).dialog({  
                                title:'系統錯誤' 
                                ,width: 600
                                , resizable: false
                                , modal: true
                                , buttons: {
                                    Ok: function() {
                                        $( this ).dialog( "close" );
                                    }
                                }
                            });
                            },
                        complete: function(XMLHttpRequest, textStatus){
                            closeWaitingDialog();
                        }
                    });
                });
        		
        		$("#closeAddMenuItemBtn").click(function() {
        			$("#menuItemDiv").dialog("close");
        		});
            });               
        //-->
        </script>        
    </c:when>
    <c:otherwise>
            查無資料
        <script type="text/javascript">
        <!--
        $(document).ready(function() {
            $( "#menuItemDiv" ).dialog({  title:'權限功能資料' ,width: 600, resizable: false, modal: true  , buttons : {
				Ok : function() {
					$(this).dialog("close");
				}
			}  });
        });
        //-->
        </script>
    </c:otherwise>
</c:choose>    